package com.example.manager;

import com.example.runnable.CollectRunnable;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 采集多线程管理
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2024-10-19 16:13
 */
public class CollectManager {

    private static final CollectManager instance = new CollectManager();

    private final Map<String, CollectRunnable> collectRunnableMap = new ConcurrentHashMap<>();

    private CollectManager() {
        // 私有构造函数，确保单例模式
    }

    public static CollectManager getInstance() {
        return instance;
    }

    public CollectRunnable get(String key) {
        return collectRunnableMap.get(key);
    }

    public void put(String key, CollectRunnable value) {
        collectRunnableMap.put(key, value);
    }

    public boolean remove(String key) {
        return collectRunnableMap.remove(key) != null;
    }

    public synchronized void clear() {
        collectRunnableMap.clear();
    }

    public List<String> getAllKeys() {
        return new ArrayList<>(collectRunnableMap.keySet());
    }


}
